﻿using System;
using System.Collections.Generic;
using Microsoft.Practices.Unity;
using Moop.Common;
using Moop.Common.IFaces;
using Moop.DataLayer.Olap.Impl;
using Moop.DataLayer.Olap.Service;
using System.Windows.Threading;
using System.Collections.Concurrent;


namespace Moop.DataLayer.Olap.Service
{
    public class TypeContainer
    {
        private static IUnityContainer _container = null;

        public static void Register()
        {
            if (_container == null) { var regs = TypeContainer.Instance.Registrations; }

            _container.RegisterType<List<string>, List<string>>(new InjectionConstructor());
            _container.RegisterType<Dictionary<string, string>, Dictionary<string, string>>(new InjectionConstructor());

            _container.RegisterType<IOlapDataService, OlapDataService>(new InjectionConstructor());
            _container.RegisterType<IOlapMetaDataService, OlapMetaDataService>(new InjectionConstructor());
            _container.RegisterType<IOlapServer, OlapServer>(new InjectionConstructor());
            _container.RegisterType<IOlapClient, OlapClient>(new InjectionConstructor());

            _container.RegisterType<IOlapDatabase, OlapDatabase>();
            _container.RegisterType<ICube, Cube>();           
            _container.RegisterType<Dictionary<string, ICube>, Dictionary<string, ICube>>(new InjectionConstructor());
            _container.RegisterType<ConcurrentDictionary<string, ICubeDimension>, ConcurrentDictionary<string, ICubeDimension>>(new InjectionConstructor());
            _container.RegisterType<ConcurrentBag<ICubeDimensionSet>, ConcurrentBag<ICubeDimensionSet>>(new InjectionConstructor());

            _container.RegisterType<ConcurrentBag<ICubeDimensionAttribute>, ConcurrentBag<ICubeDimensionAttribute>>(new InjectionConstructor());
            _container.RegisterType<ConcurrentBag<ICubeDimensionHierarchy>, ConcurrentBag<ICubeDimensionHierarchy>>(new InjectionConstructor());
            _container.RegisterType<ConcurrentBag<ICubeDimensionHierarchyLevel>, ConcurrentBag<ICubeDimensionHierarchyLevel>>(new InjectionConstructor());
            _container.RegisterType<Dictionary<string, Tuple<string, object, string>>, Dictionary<string, Tuple<string, object, string>>>(new InjectionConstructor());

            _container.RegisterType<ICubeDimension, CubeDimension>();
            _container.RegisterType<ICubeDimensionSet, CubeDimensionSet>();
            _container.RegisterType<ICubeDimensionAttribute, CubeDimensionAttribute>();
            _container.RegisterType<ICubeDimensionHierarchy, CubeDimensionHierarchy>();
            _container.RegisterType<ICubeDimensionHierarchyLevel, CubeDimensionHierarchyLevel>();

            _container.RegisterType<ICubeMeasureGroup, CubeMeasureGroup>(new InjectionConstructor());
            _container.RegisterType<List<ICubeDimension>, List<ICubeDimension>>(new InjectionConstructor());
            _container.RegisterType<Dictionary<string, ICubeMeasureGroup>, Dictionary<string, ICubeMeasureGroup>>(new InjectionConstructor());            

            _container.RegisterType<ICubeMeasure, CubeMeasure>();
            _container.RegisterType<ICubeMeasureAttribute, CubeMeasureAttribute>();
            _container.RegisterType<List<ICubeMeasureAttribute>, List<ICubeMeasureAttribute>>(new InjectionConstructor());
            _container.RegisterType<Dictionary<string, ICubeMeasure>, Dictionary<string, ICubeMeasure>>(new InjectionConstructor());
        }


        public static IUnityContainer Instance
        {
            get
            {
                if (_container == null)
                    _container = new UnityContainer();

                return _container;
            }
        }

    }
}
